from coin.exchange.okex_v5.kr_rest.native_private_client import (
    OkexSyncQueryer,
    OkexAsyncQueryer
)


class OkexFuturesNativePrivateClient(object):
  def __init__(
      self,
      *,
      key_file,
      api_host=None,
      disable_ssl=False,
      timeout=10,
      max_connections=8,
      use_async=False,
      rest_lib='pycurl',
  ):
    rest_lib = rest_lib or None
    if use_async:
      self._auth_queryer = OkexAsyncQueryer(key_file,
                                            api_host=api_host,
                                            disable_ssl=disable_ssl,
                                            timeout=timeout,
                                            max_connections=max_connections,
                                            rest_lib=rest_lib)
    else:
      self._auth_queryer = OkexSyncQueryer(key_file, api_host=api_host, timeout=timeout)

  def _query(self, method, path, params=None):
    if params is not None:
      params = {key: value for key, value in params.items() if value is not None}
    params = params or None
    return self._auth_queryer.query(method, path, params=params)

  def query_positions(self):
    method = 'GET'
    path = '/api/v5/account/positions'
    params = {'instType': 'FUTURES'}
    update = self._query(method, path, params=params)
    return update

  def query_accounts(self):
      method = 'GET'
      path = '/api/v5/account/balance'
      update = self._query(method, path)
      return update
